import redis

def execute_redis_command(redis_ip, port, password, command, output_file):
    # 连接到Redis服务器
    r = redis.StrictRedis(host=redis_ip, port=port, password=password, decode_responses=True)

    try:
        # 执行传入的Redis命令
        result = r.execute_command(command)

        # 将结果输出至指定文件
        with open(output_file, 'w') as f:
            f.write(str(result))

        print
        "命令执行成功，结果已写入%s" % output_file
    except Exception as e:
        print
        "执行命令时出现错误：", e


# 参数设置
redis_ip = '172.21.47.249'  # Redis服务器IP地址
port = 6379  # Redis服务端口
password = 'password'  # Redis认证密码
command = 'CLIENT LIST'  # 需要执行的Redis命令
output_file = '/tmp/client_list.txt'  # 输出文件路径

# 调用函数
execute_redis_command(redis_ip, port, password, command, output_file)